//
//  ShopingCartViewController.m
//  IGOtest
//
//  Created by administrator on 14-2-24.
//  Copyright (c) 2014年 administrator. All rights reserved.
//

#import "ShopingCartViewController.h"
#import "GoodsdetViewController.h"
#import "CustomCell.h"
#import "AppDelegate.h"
#import "commentViewController.h"
@interface ShopingCartViewController ()<UIAlertViewDelegate>


@end

@implementation ShopingCartViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


    self.cartTableView.delegate = self;
    self.cartTableView.dataSource = self;
    
}
- (void)viewWillAppear:(BOOL)animated
{
//    AppDelegate *del = [[UIApplication sharedApplication]delegate];
//    if (del.cartList == nil) {
//        [del.cartList addObject:self.goodss];
//    }
    //[self.cartTableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    AppDelegate *del = [[UIApplication sharedApplication]delegate];
    return del.cartList.count;


}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AppDelegate *del = [[UIApplication sharedApplication]delegate];
    static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
    
    BOOL nibsRegistered = NO;
    if (!nibsRegistered) {
        UINib *nib = [UINib nibWithNibName:@"CustomCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:CustomCellIdentifier];
        nibsRegistered = YES;
    }
    
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];
    if (cell == nil) {
        cell = [[CustomCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:CustomCellIdentifier];
    }
    NSUInteger row = [indexPath row];
    cell.name = [[del.cartList objectAtIndex:row] igoodsname];
    cell.dec = self.allprices;
    cell.loc = self.amounts;
    cell.image = [[del.cartList objectAtIndex:row] igoodsimage];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;



}


- (IBAction)return:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)buy:(id)sender {
    UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"现在骗子很多，你确定要去付钱?" delegate:self cancelButtonTitle:@"取消购买" otherButtonTitles:@"立即前往支付宝", nil];
    
    [alter show];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex ==1 ) {
        commentViewController *comment = [[commentViewController alloc]initWithNibName:@"commentViewController" bundle:nil ];
        [self presentViewController:comment animated:YES completion:nil];
    }
}
@end
